package org.six11.ss.server;

import java.io.PrintWriter;

import org.six11.ss.server.bean.Person;
import org.six11.ss.server.bean.Room;
import org.six11.ss.shared.Message;
import org.six11.util.adt.MultiState;
import static org.six11.ss.shared.GameStatusConstants.*;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class SketchDoneHandler extends AppletMessageHandler {

  /**
   * @param state
   */
  public SketchDoneHandler(MultiState state) {
    super(state);
  }

  /**
   * 
   */
  @Override
  public void handle(Message m, String sessionID, PrintWriter out) {
    Person sender = getPersonBySession(sessionID);
    if (sender == null) {
      log("Can't find that user.");
      return;
    }
    Room room = sender.getRoom();
    if (room.getCurrentGame().getCurrentRound().getSketcher().getId() == sender.getId()
        && room.getCurrentGame().getCurrentRound().getStatus().equals(STATUS_PLAY)) {
      GameHandler gh = (GameHandler) getHandler("game");
      gh.doneSketching(room.getCurrentGame().getId() + "");
    }
  }

}
